﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _15_泛型委托
{
    //泛型委托
    public delegate void SwapDelegate<T1,T2>(ref T1 t1,ref T2 t2);
    

    internal class Program
    {
        static void Main(string[] args)
        {

            SwapDelegate<int, int> otherDel = (ref int a, ref int b) =>
            {
                int temp = a;
                a = b;
                b = temp;
            };
            int value1 = 10;
            int value2 = 20;
            Console.WriteLine("交换前: a={0},b={1}", value1, value2);
            otherDel(ref value1, ref value2);
            Console.WriteLine("交换后: a={0},b={1}", value1, value2);

            SwapDelegate<ConsoleColor, ConsoleColor> swapDelegate = (ref ConsoleColor c1, ref ConsoleColor c2) =>
            {
                ConsoleColor temp = c1;
                c1 = c2;
                c2 = temp;
            };
            ConsoleColor color1 = ConsoleColor.DarkGray;
            ConsoleColor color2 = ConsoleColor.DarkYellow;

            Console.WriteLine("交换前: c1={0},c2={1}", color1, color2);
            swapDelegate(ref color1, ref color2);
            Console.WriteLine("交换后: c1={0},c2={1}", color1, color2);
            

            Console.ReadKey();

        }
    }
}
